import axiosRequest from '/@/utils/request';

/**
 * 审批权限管理
 * @method pageProcessDefinition 分页查询审批流程定义
 * @method getProcessDefinition 获取审批流程定义详情
 * @method updateProcessDefinition 修改审批流流程定义
 */
export function useApprovalApi() {
  return {
    pageProcessDefinition: async (params: {
      "pageSize": number,
      "pageNum": number
    }) => {
      return await axiosRequest({
        url: '/api/processDefinition/pageProcessDefinition',
        method: 'POST',
        data: params,
      });
    },
    getProcessDefinition: async (id: string) => {
      return await axiosRequest({
        url: `/api/processDefinition/getProcessDefinition/${id}`,
        method: 'GET',
      });
    },
    updateProcessDefinition: async (params: any) => {
      return await axiosRequest({
        url: '/api/processDefinition/updateProcessDefinition',
        method: 'POST',
        data: params,
      });
    },

    /** 变更等级的时候加两个,更项目跟进入时一个flowable: true就好了
     * @description: 审批流程的接口需要手动带上请求头：headers: { flowable: true }
     * @header flowable:true 启用审批流的请求头
     * @header flowable_current_val:string 组合流程中被修改关键值的当前值
     */
    updateProjectLevelOrTracker: async (params: any, headers: { flowableCurrentVal: string; }) => {
      return await axiosRequest({
        url: '/api/projectInfo/updateProjectLevelOrTracker',
        method: 'POST',
        data: params,
        headers: { flowable: true, 'flowable-current-val': headers.flowableCurrentVal },
      });
    },

    // 分页查询我审批的流程
    pageMyAuditProcess: async (params: any) => {
      return await axiosRequest({
        url: '/api/processInstance/pageMyAuditProcess',
        method: 'POST',
        data: params,
      });
    },
    // 分页查询我提交的审批流程
    pageApplyProcess: async (params: any) => {
      return await axiosRequest({
        url: '/api/processInstance/pageApplyProcess',
        method: 'POST',
        data: params,
      });
    },
    // 分页查询所有审批
    pageProcess: async (params: any) => {
      return await axiosRequest({
        url: '/api/processInstance/pageProcess',
        method: 'POST',
        data: params,
      });
    },
    // 查询审批流程详情
    getProcessDetail: async (params: any) => {
      return await axiosRequest({
        url: '/api/processInstance/getProcessDetail',
        method: 'POST',
        data: params,
      });
    },
    // 流程审批
    audit: async (params: any) => {
      return await axiosRequest({
        url: '/api/processInstance/audit',
        method: 'POST',
        data: params,
      });
    },

    /**
     * @description: 左侧资源类型列表
     */
    // 待我审批的总览
    auditOverview: async (params: {
      "codes": any[],
      "type": number, // 查询类型 1 = 待我审批 2 = 我参与的
      "startTime": string,
      "endTime": string,
      "createUserName": string // 创建人名称
    }) => {
      return await axiosRequest({
        url: '/api/processInstance/auditOverview',
        method: 'POST',
        data: params,
      });
    },
    // 我提交的总览
    applyOverview: async (params: {
      "codes": any[],
      "state": number,
      "startTime": string,
      "endTime": string
    }) => {
      return await axiosRequest({
        url: '/api/processInstance/applyOverview',
        method: 'POST',
        data: params,
      });
    },
    // 分页查询项目对应的审批流程
    pageProjectProcess: async (params: {
      "pageSize": number,
      "pageNum": number,
      "objId": string
    }) => {
      return await axiosRequest({
        url: '/api/processInstance/pageProjectProcess',
        method: 'POST',
        data: params,
      });
    },

    // 新的审批
    // 查询人员树
    queryUserTree: async (type: string) => {
      return await axiosRequest({
        url: `/api/userRelation/queryUserTree?type=${type}`,
        method: 'GET',
      });
    },
    // 查询人员下拉框
    querUserList: async (params: {
      "username": string,
      "postId": string
    }) => {
      return await axiosRequest({
        url: '/api/userRelation/listUser',
        method: 'POST',
        data: params,
      });
    },
    // 新增用户关系
    addUserRelation: async (params: object) => {
      return await axiosRequest({
        url: '/api/userRelation/addUserRelation',
        method: 'POST',
        data: params,
      });
    },
    // 删除人员关系
    deleteUserRelation: async (id: string) => {
      return await axiosRequest({
        url: `/api/userRelation/deleteUserRelation/${id}`,
        method: 'DELETE',
      });
    },
    // 更新人员关系
    updateUserRelation: async (params: object) => {
      return await axiosRequest({
        url: '/api/userRelation/updateUserRelation',
        method: 'PUT',
        data: params,
      });
    },
    // 根据用户id查询所有流程审批人员配置
    listProcessAuditUser: async (params: {
      "userId": string,
      "processDefinitionCode": string
    }) => {
      return await axiosRequest({
        url: '/api/confAuditUser/listProcessAuditUser',
        method: 'POST',
        data: params,
      });
    },
    // 根据用户id查询指定流程的审批人员
    listAuditUser: async (params: {
      "userId": string,
      "processDefinitionCode": string
    }) => {
      return await axiosRequest({
        url: '/api/confAuditUser/listAuditUser',
        method: 'POST',
        data: params,
      });
    },
    // 添加人员
    addAuditUser: async (params: {
      "userId": string,
      "processDefinitionCode": string,
      "relatedUserIds": any[],
      "type": number
    }) => {
      return await axiosRequest({
        url: '/api/confAuditUser/addAuditUser',
        method: 'POST',
        data: params,
      });
    },
    // 删除人员
    removeByIds: async (ids: any[]) => {
      return await axiosRequest({
        url: '/api/confAuditUser/removeByIds',
        method: 'POST',
        data: ids,
      });
    },

    // 修改抄送备注
    updateRemark: async (params: {
      "taskUserId": number,
      "remark": string
    }) => {
      return await axiosRequest({
        url: '/api/processInstance/updateRemark',
        method: 'POST',
        data: params,
      });
    },
  }
}
